package com.coda.controller;

import com.coda.adminVo.login.CaptchaVo;
import com.coda.adminVo.login.LoginVo;
import com.coda.adminVo.system.user.SystemUserInfoVo;
import com.coda.entity.UserInfo;
import com.coda.result.Result;
import com.coda.service.LoginService;
import com.wf.captcha.base.Captcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Api(tags = "用户登录")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 生成图形验证码
     */
    @GetMapping("/login/captcha")
    @ApiOperation("生成图形验证码")
    public Result<CaptchaVo> getCaptcha() {
        CaptchaVo CaptchaVo = loginService.getCaptcha();
        return Result.ok(CaptchaVo);
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        String jwt = loginService.login(loginVo);
        return Result.ok(jwt);
    }

    /**
     * 获取登录用户信息
     */
    @GetMapping("/info")
    @ApiOperation("获取登录用户信息")
    public Result<SystemUserInfoVo> getSystemUserInfo() {
        SystemUserInfoVo systemUserInfoVo = loginService.getSystemUserInfo();
        return Result.ok(systemUserInfoVo);
    }
}
